<?php
    /**
    * Show All Real Estate nearby current view
    * @author: trungdt
    * @since: feb 1, 2011
    * @version: 1.0
    * 
    * Change logs
    * Jun 1, 2011 - trungdt - first create
    * 
    */

    if (!defined('EXPONENT')) exit('');
    $config=$db->selectObject("rswidgetmodule_config","location_data = '".serialize($loc)."'");
    if ($config)
    {
        // only process if configured
        $duan_loc=exponent_core_makeLocation("duanmodule",$config->duan_src,"");
        $duan_loc_sec=serialize($duan_loc);
        
        // $id is the id of the selected dự án
        $id="";
        if (isset($_REQUEST['id']))
            $id=$_REQUEST['id'];
        $sql_where="";
        if (is_int($id))
        {
            $id=intval($id);
            $sql_where=" id != {$id}";
        }
        else
        {
            $id=_ab_safe_html_string($id);
            $sql_where=" shortname != '{$id}'";
        }

        $data=$db->selectObjects("duan"," location_data = '{$duan_loc_sec}' AND featured = 1 AND pstate=1 AND {$sql_where} LIMIT 0,10");
        foreach ($data as $k=>$v)
        {
            //location
            $province=duanmodule::_GetProvince_byID(intval($v->province_id));
            $ward = duanmodule::_GetWard_byID(intval($v->province_ward_id), ($v->province_id));
            $v->location=$ward->name;
            $v->province=clone $province;
            $v->ward=clone $ward;
            
            $v->src=unserialize($v->location_data)->src;
            // for thumbnail
            if ($v->thumbnail <= 0) {
                $v->thumbnail_path = '';
            } else {
                $file = $db->selectObject('file', 'id='.$v->thumbnail);
                $v->thumbnail_path = BASE_URL."/".$file->directory.'/'.$file->filename;
            }
        }

        $template = new template('rswidgetmodule',"_duan_nearby",$loc);
        $template->assign('projects',$data);
        $template->output();
    }
?>